package com.zimmor.mq.rocket_train.delay;

import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;

/**
 * @Author:zimmor
 * @Date: 2023/2/13 10:28
 * @Description 延迟消息发送
 * @version: 1.0.0
 */

public class DelayProducer {
    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer("producer-group1");
        producer.setNamesrvAddr("192.168.204.136:9876;192.168.204.137:9876");
        producer.start();
        for (int i = 0; i < 10; i++) {
            Message message = new Message("delay", ("delay-message" + i).getBytes());
            message.setDelayTimeLevel(3);
            SendResult send = producer.send(message);
            Thread.sleep(10000);
            System.out.println("send = " + send);
        }
        producer.shutdown();
    }
}
